using System;
using System.IO;

namespace Pegasus.IO
{
	/// <summary>
	///  Add addition features to the path class.
	/// </summary>
	public static class PathHelper
	{
		/// <summary>
		/// Given a parent path and a target path this will given you the right side
		/// of the path differences.
		/// </summary>
		/// <param name="parent">The parent.</param>
		/// <param name="filename">The filename.</param>
		/// <returns>The right path items of the filename.</returns>
		public static string GetSubPath( string parent, string filename )
		{
			string fullParent = Path.GetFullPath( parent );
			string fullFilename = Path.GetFullPath( filename );

			if( !fullFilename.ToLower().StartsWith( fullParent.ToLower() ) )
			{
				throw new ArgumentException( "The filename is not a child of the parent" );
			}

			string rightPath = fullFilename.Substring( fullParent.Length );
			rightPath = rightPath.Trim().TrimStart( '\\' );

			return rightPath;
		}
	}
}
